﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading;

namespace FiniteStateMachine
{
    public class FsmEventBase:EventArgs,IDisposable
    {
        #region members

        private bool _IsDone=false;
        public bool IsDone
        {
            get { return _IsDone; }
            set { _IsDone = value; }
        }
        private ManualResetEvent _SyncClientEvent = null;

        #endregion

        public FsmEventBase()
        {
        }

        public FsmEventBase(bool synchronized)
        {
            if(synchronized)
            {
                this._SyncClientEvent=new ManualResetEvent(false);
            }
        }

        protected internal virtual void Done()
        {
            if(this._SyncClientEvent !=null)
            {
                this._SyncClientEvent.Set();
            }
            this.IsDone = true;
        }

        public void Wait()
        {
            Debug.Assert(this._SyncClientEvent !=null);
            this._SyncClientEvent.WaitOne();
        }

        public void Dispose()
        {
            this._SyncClientEvent = null;
        }
    }
}
